package com.example.demo.controller;

import com.example.demo.model.Order;
import com.example.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    @PostMapping("/create")
    public Order create(@RequestParam Long studentId,
                        @RequestParam Long courseId,
                        @RequestParam BigDecimal amount,
                        @RequestParam String payMethod) {
        return orderService.createOrder(studentId, courseId, amount, payMethod);
    }

    @PostMapping("/notify")
    public String notify(@RequestParam Long orderId,
                         @RequestParam String email) {
        orderService.completePayment(orderId, email);
        return "支付成功";
    }

    @GetMapping("/my")
    public List<Order> list(@RequestParam Long studentId) {
        return orderService.orderRepo.findByStudentId(studentId);
    }
}
